# encoding: utf-8

import json
from tqdm import tqdm

from utils import auto_binding


with open("./datas/datas.json", "r", encoding="utf-8") as f:
    datas = json.load(f)

# print("total datas=", len(datas))  # 155188
# datas:{
#   "_id": "1100705552EA_jd:100039554695",
#   "brand": "闪迪/SANDISK",
#   "brandModel": "SDDDC3-064G-Z46",
#   "skuId": "1100705552EA",
#   "skuName": "闪迪 SDDDC3-064G-Z46 至尊高速酷柔 USB3.1双接口(Type",
#   "bindSkuName": "闪迪（SanDisk）64GB Type-C USB3.1手机U盘DDC3至尊高速酷柔 传输速度150MB/s 双接口设计 SDDDC3-064G-Z46",
#   "bindSkuUrl": "https://item.jd.com/100039554695.html",
#   "originPlatSkuId": "1100705552EA",
#   "originPlatUrl": "http://www.stbchina.cn/item.html#?itemId=1100705552EA"
# }

datas = datas[:10000]

maybe_err = []
for data in tqdm(datas):
    brand = data.get("brand", "")
    sku_name = data.get("skuName", "")
    bind_sku_name = data.get("bindSkuName")

    material_ner_data = auto_binding.process_ner(sku_name)
    bind_ner_data = auto_binding.process_ner(bind_sku_name)
    judge_result = auto_binding.is_same_sku(data, material_ner_data, bind_ner_data, bind_sku_name)

    if judge_result == "true":
        continue
    else:
        maybe_err.append(data)

if maybe_err:
    with open("./maybe_err.json", "w", encoding="utf-8") as f:
        json.dump(maybe_err, f, ensure_ascii=False)
